﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.IO;

public partial class ShopCusList : ExtBaseRpt
{
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            //加载表头 查找网格
            this.MainPanel.ColumnModel.Add(BuildColumns(mid, Session["UserID"].ToString(), "网格", frmMain));//EditPanel frmMain null
            BtnFind(sender, null);
        }
    }
    protected void MyData_Refresh(object sender, StoreReadDataEventArgs e)
    {
        BtnFind(sender, null);
    }
    protected void BtnFind(object sender, DirectEventArgs e)
    {
        StoreColumns(MainStore, mid, "网格");
        string sql = string.Empty;
        //sql = mydb.DM_GetExecuteScalarObj("select weburl from sys_modules where parentid=" + mid + " and modulecode='网格'").ToString();

        sql = string.Format(@"SELECT [ShopID]
      ,[ShopCode]
      ,[ShopName]
      ,[FullName]
      ,convert(varchar(10),KdDate,23) as [KdDate]
      ,case when FlatImg <> '' then FlatImg + '?w=40' end as [FlatImg]
      ,[GeteWidth]
      ,[PassWidth1]
      ,[PassWidth2]
      ,[PassWidth3]
      ,[PassWidth4]
      ,[PassWidth5]
      ,[PassWidth6]
      ,case when DeviceImg1 <> '' then DeviceImg1 + '?w=40' end as [DeviceImg1]
      ,case when DeviceImg2 <> '' then DeviceImg2 + '?w=40' end as [DeviceImg2]
      ,case when DeviceImg3 <> '' then DeviceImg3 + '?w=40' end as [DeviceImg3]
      ,case when DeviceImg4 <> '' then DeviceImg4 + '?w=40' end as [DeviceImg4]
      ,case when DeviceImg5 <> '' then DeviceImg5 + '?w=40' end as [DeviceImg5]
      ,case when DeviceImg6 <> '' then DeviceImg6 + '?w=40' end as [DeviceImg6]
      ,case when DeviceImg7 <> '' then DeviceImg7 + '?w=40' end as [DeviceImg7]
      ,[IsFine]
      ,[ShopStateID]
      ,[Creator]
      ,[DeviceType]
      ,convert(varchar(100),CreateDate,121) as [CreateDate]
FROM Bas_MrjCusShop 
WHERE 1=1 and shopstateid='00000000000011' ");

        System.Data.DataSet ds = new System.Data.DataSet();
        ds = mydb.DM_GetDateSet(sql + " and (shopcode like '%" + txtshop.Text + "%' or shopname like '%" + txtshop.Text + "%')"); //测试 and shopcode='411043j'
        int numDs = ds.Tables[0].Rows.Count;
        MainStore.DataSource = ds;
        MainStore.DataBind();
        
    }
    protected void BtnGetShop(object sender, DirectEventArgs e)
    {
        //获取卡门店铺资料 修改同步数据时增加 开店时间：kddate  店铺状态：shopstateid 两个字段 修改时间：2017-04-11
        string sql = @"insert into Bas_MrjCusShop(shopid,shopcode,shopname,fullname,kddate,shopstateid)
                    select a.shopid,a.shopcode,a.shopname,a.shopfullname,a.kddate,a.shopstateid from V_ShopList a
                    left join Bas_MrjCusShop b on b.ShopID = a.ShopID
                    where isnull(b.shopid,'')='' and a.shopfullname not like'%禁用%'";
        //更新
        sql += @" update a set ShopName = b.shopname,
		                         FullName = b.ShopFullName,
			                     KdDate = b.kddate,
			                     ShopStateID = b.ShopStateID,
			                     ModifyDate = b.ModifyDTM
                from Bas_MrjCusShop a
                inner join V_Shop b on b.shopid = a.ShopID
                where b.ModifyDTM > a.ModifyDate ";
        if (mydb.DM_ExecuteNonQuery(sql) != -1)
        {
            ShowBox("加载成功！");
        }
        else
        {
            ShowBox("加载失败！");
        }
        BtnFind(null, null);
    }

    //protected void MultiUpload1_FileUpload(object sender, FileUploadEventArgs e)
    //{
    //    //System.Threading.Thread.Sleep(3000); // Just for testing
    //    //上传图片的扩展名
    //    string type = e.FileName.Substring(e.FileName.LastIndexOf('.'));
    //    //保存图片的文件名
    //    string saveName = Guid.NewGuid().ToString() + type;
    //    string path = Server.MapPath("../UploadFile/") + saveName;
    //    e.PostedFile.SaveAs(path);
    //    RowSelectionModel sm = this.MainPanel.GetSelectionModel() as RowSelectionModel;
    //    string id = sm.SelectedRecordID;
    //    string field = "";
    //    RadioGroup1.CheckedItems.ForEach(delegate(Radio radio)
    //    {
    //        field = radio.InputValue.ToString();
    //    });
    //    string sql = "update Bas_MrjCusShop set " + field + "='../UploadFile/" + saveName + "' where ShopID = '" + id + "'";
    //    if (mydb.DM_ExecuteNonQuery(sql) != -1)
    //    {
    //        ShowBox("上传成功！");
    //    }
    //    else
    //    {
    //        ShowBox("上传失败！");
    //    }
    //}
    //protected void BtnDeleteImg(object sender, DirectEventArgs e)
    //{
    //    RowSelectionModel sm = this.MainPanel.GetSelectionModel() as RowSelectionModel;
    //    string id = sm.SelectedRecordID;
    //    if (id == "")
    //    {
    //        ShowBox("请选择要删除图片的店铺！");
    //        return;
    //    }
    //    string field = "";
    //    RadioGroup1.CheckedItems.ForEach(delegate(Radio radio)
    //    {
    //        field = radio.InputValue.ToString();
    //    });
    //    string sql = "update Bas_MrjCusShop set " + field + "='' where ShopID = '" + id + "'";
    //    if (mydb.DM_ExecuteNonQuery(sql) != -1)
    //    {
    //        ShowBox("删除成功！");
    //        BtnFind(null, null);
    //    }
    //    else
    //    {
    //        ShowBox("删除失败！");
    //    }
    //}

//    [DirectMethod(Namespace = "CompanyX")]
//    public void BtnDelete()
//    {
//        RowSelectionModel sm = this.MainPanel.GetSelectionModel() as RowSelectionModel;
//        string id = sm.SelectedRecordID;
//         string sql = "";
//        string tablename = mydb.DM_GetExecuteScalarObj("select moduletab from sys_modules where parentid=" + mid + " and modulecode='网格'").ToString();
//        string keyname = mydb.DM_GetExecuteScalarObj(@"SELECT FieldName FROM Sys_ModulesLayout WHERE MID IN(select MId from sys_modules where parentid=" + mid + @" and modulecode='网格')
//                                                        AND isnull(IsKeyId,0) = 1").ToString();
//        sql = "delete from " + tablename + " where " + keyname + " = "+id;
//        if (mydb.DM_ExecuteNonQuery(sql) != -1)
//        {
//            ShowBox("删除成功！");
//        }
//        else
//        {
//            ShowBox("删除失败！");
//        }
//    }
//    [DirectMethod(Namespace = "CompanyX")]
//    public void BtnSave(string fields,string vals)
//    {
//        //保存数据
//        //fields = fields.TrimEnd(',');
//        //vals = vals.TrimEnd(',');
//        RowSelectionModel sm = this.MainPanel.GetSelectionModel() as RowSelectionModel;
//        string id = sm.SelectedRecordID;
//        ShowBox("ID:" + id);
//        string sql = "";
//        string tablename = mydb.DM_GetExecuteScalarObj("select moduletab from sys_modules where parentid=" + mid + " and modulecode='网格'").ToString();
//        string keyname = mydb.DM_GetExecuteScalarObj(@"SELECT FieldName FROM Sys_ModulesLayout WHERE MID IN(select MId from sys_modules where parentid=" + mid + @" and modulecode='网格')
//                                                        AND isnull(IsKeyId,0) = 1").ToString();
//        //新增
//        if (this.ActState.Value.ToString() == "Add")
//        {
//            string[] flist = fields.Split(',');
//            string[] vlist = vals.Split(',');
//            string flstr="",valstr="",tempstr = "";
//            for (int i = 0; i < flist.Length; i++)
//            {
//                flstr += flist[i]+",";
//                if (vlist[i] == "" && flist[i].ToLower() != "creater"
//                   && flist[i].ToLower() != "createdate")
//                {
//                    tempstr = "''";
//                }
//                else if (vlist[i].ToLower() == "true")
//                {
//                    tempstr = "1";
//                }
//                else if (vlist[i].ToLower() == "false")
//                {
//                    tempstr = "0";
//                }
//                else if (flist[i].ToLower() == "creater")
//                {
//                    tempstr = "'"+Session["UserCode"].ToString()+"'";
//                }
//                else if (flist[i].ToLower() == "createdate")
//                {
//                    tempstr = "getdate()";
//                }
//                else
//                {
//                    tempstr = "'"+vlist[i]+"'";
//                }
//                valstr += tempstr+",";
//            }
//            flstr = flstr.TrimEnd(',');
//            valstr = valstr.TrimEnd(',');
//            sql = "insert into " + tablename + "(" + flstr + ")values(" + valstr + ")";
//        }
//        else
//        {
//            //修改

//            string[] flist = fields.Split(',');
//            string[] vlist = vals.Split(',');
//            string flstr = "", tempstr = "";
//            for (int i = 0; i < flist.Length; i++)
//            {
//                if (vlist[i] == "" && flist[i].ToLower() != "creator"
//                    && flist[i].ToLower() != "createdate")
//                {
//                    tempstr = "''";
//                }
//                else if (vlist[i].ToLower() == "true")
//                {
//                    tempstr = "1";
//                }
//                else if (vlist[i].ToLower() == "false")
//                {
//                    tempstr = "0";
//                }
//                else if (flist[i].ToLower() == "creator")
//                {
//                    tempstr = "'" + Session["UserCode"].ToString() + "'";
//                }
//                else if (flist[i].ToLower() == "createdate")
//                {
//                    tempstr = "getdate()";
//                }
//                else
//                {
//                    tempstr = "'" + vlist[i] + "'";
//                }
//                flstr += flist[i]+"="+ tempstr + ",";
//            }
//            flstr = flstr.TrimEnd(',');
//            sql = "update " + tablename + " set " + flstr + " where " + keyname + " = '" + id + "'";
//        }
//        //X.Msg.Alert("Submit", sql).Show();
//        //this.Panel3.Collapsed = true;
//        if (mydb.DM_ExecuteNonQuery(sql) != -1)
//        {
//            ShowBox("保存成功！");
//            this.ActState.SetValue("Edit");
//        }
//        else
//        {
//            ShowBox("数据保存失败！");
//        }
//        BtnFind(null, null);
//    }
//    protected void SaveData(object sender, DirectEventArgs e)
//    {

//    }

    /// <summary>
    /// 根据业务需求只做修改保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMainSave_Click(object sender, DirectEventArgs e)
    {
        //{"ShopID":"KM000444","ShopCode":"411043J","ShopName":"濮阳旭龙大厦2号店","GeteWidth":"9","PassWidth1":"8","PassWidth2":"7",
        //"PassWidth3":"6","PassWidth4":"5","PassWidth5":"4","PassWidth6":"3","Creator":"10006","CreateDate":"2017-04-19 10:08:59.200","IsFine":true,"DeviceType":"M1S-18"}
        //接收客户端传过来的model参数
        string shopJson = e.ExtraParams["model"];
        //反序列化为ShopCus对象
        var model = JSON.Deserialize<ShopCus>(shopJson);
        if (string.IsNullOrEmpty(model.ShopID))
        {
            e.ErrorMessage = "店铺ID不能为空";
            e.Success = false;
            return;
        }
        if (string.IsNullOrEmpty(model.ShopCode))
        {
            e.ErrorMessage = "店铺代码不能为空";
            e.Success = false;
            return;
        }

        try
        {
            model.Creator = Session["UserCode"].ToString();
            int isFine = 0;
            if (model.IsFine)
            {
                isFine = 1;
            }
            string sql = string.Empty;
            sql = string.Format(@"UPDATE Bas_MrjCusShop SET ShopCode='{0}',ShopName='{1}',GeteWidth='{2}',PassWidth1='{3}',PassWidth2='{4}',PassWidth3='{5}',PassWidth4='{6}',PassWidth5='{7}',PassWidth6='{8}',Creator='{9}',CreateDate=getdate(),IsFine={10},DeviceType='{11}' WHERE ShopID='{12}' ",
                model.ShopCode, model.ShopName, model.GeteWidth, model.PassWidth1, model.PassWidth2, model.PassWidth3, model.PassWidth4, model.PassWidth5, model.PassWidth6, model.Creator, isFine, model.DeviceType, model.ShopID);//DeviceType='{11}'

            if (mydb.DM_ExecuteNonQuery(sql) != -1)
            {
                e.Success = true;
                BtnFind(null, null);
            }
            else
            {
                e.ErrorMessage = "数据保存失败";
                e.Success = false;
            }

            
        }
        catch (Exception ex)
        {
            //logs...ex
            e.ErrorMessage = "数据保存失败" + ex.Message;
            e.Success = false;
        }

    }

    /// <summary>
    /// 根据业务需求删除选中的数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, DirectEventArgs e)
    {
        //接收客户端传过来的model参数
        string shopJson = e.ExtraParams["model"];
        //反序列化为ShopCus对象
        var model = JSON.Deserialize<ShopCus>(shopJson);
        if (string.IsNullOrEmpty(model.ShopID))
        {
            e.ErrorMessage = "店铺ID不能为空";
            e.Success = false;
            return;
        }

        try
        {
            string sql = string.Empty;
            sql = string.Format(@"DELETE FROM Bas_MrjCusShop WHERE ShopID='{0}' ", model.ShopID);

            if (mydb.DM_ExecuteNonQuery(sql) != -1)
            {
                e.Success = true;
            }
            else
            {
                e.ErrorMessage = "数据删除失败";
                e.Success = false;
            }


        }
        catch (Exception ex)
        {
            //logs...ex
            e.ErrorMessage = "数据删除失败" + ex.Message;
            e.Success = false;
        }
    }

    /// <summary>
    /// 根据业务上传图片到指定的店铺
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnImgSave_Click(object sender, DirectEventArgs e)
    {
        //接收客户端传过来的model参数
        string shopJson = e.ExtraParams["model"];
        //反序列化为ShopImg对象
        var model = JSON.Deserialize<ShopImg>(shopJson);
        if (string.IsNullOrEmpty(model.ShopCode))
        {
            e.ErrorMessage = "店铺编码不能为空";
            e.Success = false;
            return;
        }
        //if (string.IsNullOrEmpty(model.Remarks))
        //{
        //    e.ErrorMessage = "图片描述不能为空";
        //    e.Success = false;
        //    return;
        //}

        try
        {
            string UploadFile = "";
            if (this.UploadFile.HasFile)
            {
                UploadFile = this.UploadFile.PostedFile.FileName.ToString();
                int FileSize = Int32.Parse(this.UploadFile.PostedFile.ContentLength.ToString());
                if (FileSize > 5 * 1024 * 1024)
                {
                    //X.Msg.Alert("提示", "上传文件过大！").Show();
                    e.ErrorMessage = "上传文件过大！";
                    e.Success = false;
                    return;
                }
                string strFileType = this.UploadFile.PostedFile.FileName;//获取文件后缀
                strFileType = strFileType.Substring(strFileType.LastIndexOf('.')).ToUpper();
                if (!(strFileType == ".BMP" || strFileType == ".GIF" || strFileType == ".JPG" || strFileType == ".PNG"))
                {
                    e.ErrorMessage = "文件格式不正确！只支持.BMP .GIF .JPG .PNG 格式";
                    e.Success = false;
                    return;
                }

                //保存图片的文件名
                model.Guid = Guid.NewGuid().ToString();
                string strSaveFileName = model.Guid + strFileType;
                string strPath = Server.MapPath("../UploadFile/") + strSaveFileName;
                model.Url = "../UploadFile/" + strSaveFileName;
                this.UploadFile.PostedFile.SaveAs(strPath);

                string sqlShopImg = string.Empty;
                sqlShopImg = string.Format(@"INSERT INTO Bas_MrjShopImg(ShopCode,[Guid],ImgType) VALUES ('{0}','{1}',{2})", model.ShopCode, model.Guid, model.ImgType);
                string sqlImgUrl = string.Empty;
                sqlImgUrl = string.Format(@"INSERT INTO Bas_ImgUrl([Guid],Url,Remarks,IsFirstImg,CreateDate) VALUES ('{0}','{1}','{2}',{3},getdate())", model.Guid, model.Url, model.Remarks, model.IsFirstImg == true ? 1 : 0);

                if (mydb.DM_ExecuteNonQuery(sqlShopImg) != -1 && mydb.DM_ExecuteNonQuery(sqlImgUrl) != -1)
                {
                    e.Success = true;
                }
                else
                {
                    e.ErrorMessage = "保存图片失败";
                    e.Success = false;
                }
            }
            else
            {
                e.ErrorMessage = "请选择图片";
                e.Success = false;
            }
        }
        catch (Exception ex)
        {
            //logs...ex
            e.ErrorMessage = "保存图片失败" + ex.Message;
            e.Success = false;
        }
    }

    [DirectMethod(Namespace = "CompanyX")]
    public string getImgUrl(string JsonParams)
    {
        //反序列化为ShopCus对象
        var model = JSON.Deserialize<ShopCus>(JsonParams);
        string strResult = string.Empty;
        if (string.IsNullOrEmpty(model.ShopCode))
        {
            strResult = "店铺ID不能为空";
            return strResult;
        }

        try
        {
            string sqlImgType1 = string.Empty;
            sqlImgType1 = string.Format(@"SELECT TOP 1 MSI.ShopCode,IU.Guid,IU.Url,IU.Remarks FROM Bas_MrjShopImg AS MSI LEFT JOIN Bas_ImgUrl AS IU ON MSI.Guid=IU.Guid WHERE 1=1 AND MSI.ShopCode='{0}' AND IU.IsEnable=1 AND MSI.ImgType=1 ORDER BY IU.CreateDate desc ", model.ShopCode);
            System.Data.DataSet dsImgType1 = new System.Data.DataSet();
            dsImgType1 = mydb.DM_GetDateSet(sqlImgType1);
            if (dsImgType1 != null && dsImgType1.Tables[0].Rows.Count > 0)
            {
                this.imgType1Url1.ImageUrl = dsImgType1.Tables[0].Rows[0]["Url"].ToString();
                this.imgType1Url1.AlternateText = dsImgType1.Tables[0].Rows[0]["Guid"].ToString();
                this.hidImgType1Title1.Text = dsImgType1.Tables[0].Rows[0]["Remarks"].ToString();
            }
            else
            {
                this.imgType1Url1.ImageUrl = "";
                this.imgType1Url1.AlternateText = "";
                this.hidImgType1Title1.Text = "";
            }

            string sqlImgType2 = string.Empty;
            sqlImgType2 = string.Format(@"SELECT TOP 1 MSI.ShopCode,IU.Guid,IU.Url,IU.Remarks FROM Bas_MrjShopImg AS MSI LEFT JOIN Bas_ImgUrl AS IU ON MSI.Guid=IU.Guid WHERE 1=1 AND MSI.ShopCode='{0}' AND IU.IsEnable=1 AND MSI.ImgType=2 ORDER BY IU.CreateDate desc ", model.ShopCode);
            System.Data.DataSet dsImgType2 = new System.Data.DataSet();
            dsImgType2 = mydb.DM_GetDateSet(sqlImgType2);
            if (dsImgType2 != null && dsImgType2.Tables[0].Rows.Count > 0)
            {
                this.imgType2Url1.ImageUrl = dsImgType2.Tables[0].Rows[0]["Url"].ToString();
                this.imgType2Url1.AlternateText = dsImgType2.Tables[0].Rows[0]["Guid"].ToString();
                this.hidImgType2Title1.Text = dsImgType2.Tables[0].Rows[0]["Remarks"].ToString();
            }
            else
            {
                this.imgType2Url1.ImageUrl = "";
                this.imgType2Url1.AlternateText = "";
                this.hidImgType2Title1.Text = "";
            }

            string sqlImgType3 = string.Empty;
            string strImgType3Url1 = "";
            string strImgType3Url2 = "";
            string strImgType3Url3 = "";
            string strImgType3Url4 = "";
            string strImgType3Url5 = "";
            string strImgType3Url6 = "";
            string strImgType3Url7 = "";
            this.imgType3Url1.AlternateText = "";
            this.imgType3Url2.AlternateText = "";
            this.imgType3Url3.AlternateText = "";
            this.imgType3Url4.AlternateText = "";
            this.imgType3Url5.AlternateText = "";
            this.imgType3Url6.AlternateText = "";
            this.imgType3Url7.AlternateText = "";
            this.hidImgType3Title1.Text = "";
            this.hidImgType3Title2.Text = "";
            this.hidImgType3Title3.Text = "";
            this.hidImgType3Title4.Text = "";
            this.hidImgType3Title5.Text = "";
            this.hidImgType3Title6.Text = "";
            this.hidImgType3Title7.Text = "";
            sqlImgType3 = string.Format(@"SELECT TOP 7 MSI.ShopCode,IU.Guid,IU.Url,IU.Remarks FROM Bas_MrjShopImg AS MSI LEFT JOIN Bas_ImgUrl AS IU ON MSI.Guid=IU.Guid WHERE 1=1 AND MSI.ShopCode='{0}' AND IU.IsEnable=1 AND MSI.ImgType=3 ORDER BY IU.CreateDate desc ", model.ShopCode);
            System.Data.DataSet dsImgType3 = new System.Data.DataSet();
            dsImgType3 = mydb.DM_GetDateSet(sqlImgType3);
            if (dsImgType3 != null && dsImgType3.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsImgType3.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        strImgType3Url1 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url1.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title1.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 1)
                    {
                        strImgType3Url2 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url2.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title2.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 2)
                    {
                        strImgType3Url3 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url3.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title3.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 3)
                    {
                        strImgType3Url4 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url4.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title4.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 4)
                    {
                        strImgType3Url5 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url5.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title5.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 5)
                    {
                        strImgType3Url6 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url6.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title6.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                    else if (i == 6)
                    {
                        strImgType3Url7 = dsImgType3.Tables[0].Rows[i]["Url"].ToString();
                        this.imgType3Url7.AlternateText = dsImgType3.Tables[0].Rows[i]["Guid"].ToString();
                        this.hidImgType3Title7.Text = dsImgType3.Tables[0].Rows[i]["Remarks"].ToString();
                    }
                }
            }
            this.imgType3Url1.ImageUrl = strImgType3Url1;
            this.imgType3Url2.ImageUrl = strImgType3Url2;
            this.imgType3Url3.ImageUrl = strImgType3Url3;
            this.imgType3Url4.ImageUrl = strImgType3Url4;
            this.imgType3Url5.ImageUrl = strImgType3Url5;
            this.imgType3Url6.ImageUrl = strImgType3Url6;
            this.imgType3Url7.ImageUrl = strImgType3Url7;

            string sqlImgType4 = string.Empty;
            string strImgType4Url1 = "";
            string strImgType4Url2 = "";
            string strImgType4Url3 = "";
            string strImgType4Url4 = "";
            string strImgType4Url5 = "";
            string strImgType4Url6 = "";
            string strImgType4Url7 = "";
            string strImgType4Url8 = "";
            this.imgType4Url1.AlternateText = "";
            this.imgType4Url2.AlternateText = "";
            this.imgType4Url3.AlternateText = "";
            this.imgType4Url4.AlternateText = "";
            this.imgType4Url5.AlternateText = "";
            this.imgType4Url6.AlternateText = "";
            this.imgType4Url7.AlternateText = "";
            this.imgType4Url8.AlternateText = "";
            this.hidImgType4Title1.Text = "";
            this.hidImgType4Title2.Text = "";
            this.hidImgType4Title3.Text = "";
            this.hidImgType4Title4.Text = "";
            this.hidImgType4Title5.Text = "";
            this.hidImgType4Title6.Text = "";
            this.hidImgType4Title7.Text = "";
            this.hidImgType4Title8.Text = "";
            sqlImgType4 = string.Format(@"SELECT TOP 8 MSI.ShopCode,IU.Guid,IU.Url,IU.Remarks FROM Bas_MrjShopImg AS MSI LEFT JOIN Bas_ImgUrl AS IU ON MSI.Guid=IU.Guid WHERE 1=1 AND MSI.ShopCode='{0}' AND IU.IsEnable=1 AND MSI.ImgType=4 ORDER BY IU.CreateDate desc ", model.ShopCode);
            System.Data.DataSet dsImgType4 = new System.Data.DataSet();
            dsImgType4 = mydb.DM_GetDateSet(sqlImgType4);
            if (dsImgType4 != null && dsImgType4.Tables[0].Rows.Count > 0)
            {
                for (int j = 0; j < dsImgType4.Tables[0].Rows.Count; j++)
                {
                    if (j == 0)
                    {
                        strImgType4Url1 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url1.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title1.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 1)
                    {
                        strImgType4Url2 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url2.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title2.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 2)
                    {
                        strImgType4Url3 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url3.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title3.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 3)
                    {
                        strImgType4Url4 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url4.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title4.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 4)
                    {
                        strImgType4Url5 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url5.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title5.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 5)
                    {
                        strImgType4Url6 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url6.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title6.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 6)
                    {
                        strImgType4Url7 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url7.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title7.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                    else if (j == 7)
                    {
                        strImgType4Url8 = dsImgType4.Tables[0].Rows[j]["Url"].ToString();
                        this.imgType4Url8.AlternateText = dsImgType4.Tables[0].Rows[j]["Guid"].ToString();
                        this.hidImgType4Title8.Text = dsImgType4.Tables[0].Rows[j]["Remarks"].ToString();
                    }
                }
            }
            this.imgType4Url1.ImageUrl = strImgType4Url1;
            this.imgType4Url2.ImageUrl = strImgType4Url2;
            this.imgType4Url3.ImageUrl = strImgType4Url3;
            this.imgType4Url4.ImageUrl = strImgType4Url4;
            this.imgType4Url5.ImageUrl = strImgType4Url5;
            this.imgType4Url6.ImageUrl = strImgType4Url6;
            this.imgType4Url7.ImageUrl = strImgType4Url7;
            this.imgType4Url8.ImageUrl = strImgType4Url8;

            return strResult;
        }
        catch (Exception ex)
        {
            strResult = string.Format("加载图片失败{0}", ex.Message);
            return strResult;
        }
    }

    //删除图片
    [DirectMethod(Namespace = "CompanyX")]
    public int delImg(string JsonParams)
    {
        //反序列化为ShopImg对象
        var model = JSON.Deserialize<ShopImg>(JsonParams);
        if (string.IsNullOrEmpty(model.Guid))
        {
            return 0;
        }

        string sqlShopImg = string.Empty;
        sqlShopImg = string.Format(@"DELETE FROM Bas_MrjShopImg WHERE 1=1 AND Guid='{0}' ", model.Guid);
        string sqlImgUrl = string.Empty;
        sqlImgUrl = string.Format(@"DELETE FROM Bas_ImgUrl WHERE 1=1 AND Guid='{0}' ", model.Guid);

        if (mydb.DM_ExecuteNonQuery(sqlShopImg) != -1)
        {
            if (mydb.DM_ExecuteNonQuery(sqlImgUrl) != -1)
            {
                try
                {
                    string strPath = Server.MapPath(model.Url);
                    if (File.Exists(strPath))
                    {
                        File.Delete(strPath);
                    }
                }
                catch{ }
            }
            return 1;
        }
        else
        {
            return 0;
        }
    }

    /// <summary>
    /// 接收修改参数实体类
    /// </summary>
    public class ShopCus
    {
        /// <summary>
        /// 店铺ID
        /// </summary>
        public string ShopID { get; set; }
        /// <summary>
        /// 店铺代码
        /// </summary>
        public string ShopCode { get; set; }
        /// <summary>
        /// 店铺简称
        /// </summary>
        public string ShopName { get; set; }
        /// <summary>
        /// 门宽
        /// </summary>
        public string GeteWidth { get; set; }
        /// <summary>
        /// 通道宽1
        /// </summary>
        public string PassWidth1 { get; set; }
        /// <summary>
        /// 通道宽2
        /// </summary>
        public string PassWidth2 { get; set; }
        /// <summary>
        /// 通道宽3
        /// </summary>
        public string PassWidth3 { get; set; }
        /// <summary>
        /// 通道宽4
        /// </summary>
        public string PassWidth4 { get; set; }
        /// <summary>
        /// 通道宽5
        /// </summary>
        public string PassWidth5 { get; set; }
        /// <summary>
        /// 通道宽6
        /// </summary>
        public string PassWidth6 { get; set; }
        /// <summary>
        /// 操作员
        /// </summary>
        public string Creator { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateDate { get; set; }
        /// <summary>
        /// 是否符合
        /// </summary>
        public bool IsFine { get; set; }
        /// <summary>
        /// 设备类型
        /// </summary>
        public string DeviceType{ get; set; }
    }

    /// <summary>
    /// 接收创建图片请求参数
    /// </summary>
    public class ShopImg
    {
        //{"ImgType":"1","Remarks":"999","UploadFile":"101 - 副本 (3).png","IsFirstImg":true,"ShopCode":"411043J"}
        /// <summary>
        /// 店铺代码
        /// </summary>
        public string ShopCode { get; set; }
        /// <summary>
        /// 图片Guid标识
        /// </summary>
        public string Guid { get; set; }
        /// <summary>
        /// 图片类型 1：平面图 2：布点图 3：设备图 4：通道图
        /// </summary>
        public string ImgType { get; set; }
        /// <summary>
        /// 图片Url地址
        /// </summary>
        public string Url { get; set; }
        /// <summary>
        /// 图片备注描述
        /// </summary>
        public string Remarks { get; set; }
        /// <summary>
        /// 图片原名
        /// </summary>
        public string UploadFile { get; set; }
        /// <summary>
        /// 是否设置为首图
        /// </summary>
        public bool IsFirstImg { get; set; }
    }
}